package com.ffyc.ssm.util;

import com.ffyc.ssm.modle.Admin;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class LoginInterceptor implements HandlerInterceptor {
    /*
        预处理 - 进入到控制器之前， 如果为false 不进入控制器
                                如果为true 进入控制器
     */
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        HttpSession session = request.getSession();
        Admin admin =(Admin) session.getAttribute("admin");
        if (admin==null){
           // response.getWriter().print(202);
            return false;
        }else {
            return true;
        }

    }

/*
        控制器执行完后，执行
    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {

    }
     整个请求完成，执行
    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {

    }*/
}
